package com.example.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

@Configuration
public class MyBatisPlusConfig {
    @Value("${spring.datasource.driver-class-name}")
    private String driverClassName;
    @Value("${spring.datasource.url}")
    private String url;
    @Value("${spring.datasource.username}")
    private String username;
    @Value("${spring.datasource.password}")
    private String password;

    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor page = new PaginationInterceptor();
        return page;
    }
    @Bean
    @Primary
    public DataSource dataSource() {
        DruidDataSource dataSource=new DruidDataSource();
        dataSource.setUrl(url);
//        dataSource.setUsername(username);
//        dataSource.setPassword(password);
        dataSource.setDriverClassName(driverClassName);
        dataSource.addConnectionProperty("user",username);
        dataSource.addConnectionProperty("password",password);
//        dataSource.setInitialSize();
//        dataSource.setMinIdle();
//        dataSource.setMaxActive();
//        dataSource.setMaxWait();
//        dataSource.setPoolPreparedStatements();
        return dataSource;
    }
}